﻿package plugin.instances.game
{
    import com.core.*;
    import com.sh.game.util.*;
    import flash.utils.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.instances.*;
    import uiresource.instances.ui.*;
    import view.mornExtends.*;

    public class YaoQianShuGame extends YqsUI implements IInstance
    {
        private var nextFreshTime:int = 0;
        private var _instance:Object;

        public function YaoQianShuGame()
        {
            return;
        }// end function

        public function initShow(param1:Object, param2:Dictionary) : void
        {
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            this._instance = param1;
            this.showItem(param1.show);
            shuoming.toolTip = param1.tips.replace(/#""#/g, "\n");
            label_times.text = "--";
            var _loc_3:* = param2[InstancesPublic.INITYAOQIANSHU];
            if (_loc_3 == null)
            {
                return;
            }
            if (_loc_3.hasOwnProperty("wave"))
            {
                label_boshu.text = _loc_3.wave;
                label_num3.text = _loc_3.aliveMonsterCaount + "/25";
                label_num2.text = "击杀" + _loc_3.refreshBigMonsterCount + "/50树妖";
            }
            if (_loc_3.hasOwnProperty("expObtainCount"))
            {
                label_jinbi.text = _loc_3.expObtainCount;
                label_liquan.text = _loc_3.liquanObtainCount;
            }
            if (_loc_3.hasOwnProperty("nextFreshTime"))
            {
                this.nextFreshTime = _loc_3.nextFreshTime;
                _loc_4 = Number(ModelProxy.getValue("data", "servertime") + getTimer()) / 1000;
                if (this.nextFreshTime - _loc_4 >= 0)
                {
                    label_times.width = 200;
                    label_times.text = TimeDataFormatUtil.getLeftTimeStr3(this.nextFreshTime - _loc_4);
                }
                _loc_5 = this.nextFreshTime - _loc_4;
                if (_loc_5 < 0)
                {
                    _loc_5 = 0;
                }
                if (_loc_5 <= 30)
                {
                    ModelProxy.change("mainui", "counter", {type:6, value:_loc_5});
                }
            }
            return;
        }// end function

        private function showItem(param1:String) : void
        {
            var _loc_2:* = new ItemSplit();
            var _loc_3:* = _loc_2.doSplits(param1, "&", "/", "#");
            list.array = _loc_3[0];
            list.renderHandler = new Handler(this.itemRender);
            return;
        }// end function

        private function itemRender(param1:Component, param2:int) : void
        {
            if (param2 < list.length)
            {
                (param1.getChildByName("item") as FlashItem).data = list.array[param2];
            }
            return;
        }// end function

        public function updateShow(param1:int, param2:Object) : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            switch(param1)
            {
                case InstancesPublic.TIMECHECKER:
                {
                    _loc_5 = int(param2);
                    txt_time.text = TimeDataFormatUtil.getLeftTimeStr3(_loc_5);
                    _loc_3 = Number(ModelProxy.getValue("data", "servertime") + getTimer()) / 1000;
                    _loc_4 = this.nextFreshTime - _loc_3;
                    if (_loc_4 >= 0)
                    {
                        label_times.text = TimeDataFormatUtil.getLeftTimeStr3(this.nextFreshTime - _loc_3);
                    }
                    if (_loc_4 == 30)
                    {
                        ModelProxy.change("mainui", "counter", {type:6, value:_loc_4});
                    }
                    break;
                }
                case InstancesPublic.INITYAOQIANSHU:
                {
                    label_boshu.text = param2.wave;
                    label_num3.text = param2.aliveMonsterCaount + "/25";
                    this.nextFreshTime = param2.nextFreshTime;
                    label_num2.text = "击杀" + param2.refreshBigMonsterCount + "/50树妖";
                    _loc_3 = Number(ModelProxy.getValue("data", "servertime") + getTimer()) / 1000;
                    _loc_4 = this.nextFreshTime - _loc_3;
                    if (_loc_4 < 0)
                    {
                        _loc_4 = 0;
                    }
                    if (param2.aliveMonsterCaount == 0)
                    {
                        ModelProxy.change("mainui", "counter", {type:6, value:_loc_4});
                    }
                    break;
                }
                case InstancesPublic.YAOQIANSHULIQUAN:
                {
                    label_jinbi.text = param2.expObtainCount;
                    label_liquan.text = param2.liquanObtainCount;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function destroyShow(param1:Dictionary) : void
        {
            return;
        }// end function

        public function initEvent() : void
        {
            btn_tuichu.clickHandler = new Handler(this.doClose);
            return;
        }// end function

        private function doClose() : void
        {
            ModelProxy.change("zone", "exitInstance", null);
            return;
        }// end function

        public function removeEvent() : void
        {
            return;
        }// end function

    }
}
